package com.fla.millioner.ui;

import com.alone1672.millioner.R;
import com.danikula.aibolit.Aibolit;
import com.danikula.aibolit.annotation.InjectOnClickListener;
import com.fla.millioner.ui.HelpUtils.AnswerModel;
import com.fla.millioner.ui.support.AndroidUtils;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
public class ZalDialog extends Dialog {
    private View[] rows;
    private TextView[] percentViews;

    public ZalDialog(Context context, int level, AnswerModel[] answerModels) {
        super(context);

        setTitle("Помощь зала");
        Aibolit.setInjectedContentView(this, R.layout.zal_dialog);

        rows = new View[] {findViewById(R.id.row1), findViewById(R.id.row2), findViewById(R.id.row3), findViewById(R.id.row4)};
        percentViews = new TextView[] {(TextView) findViewById(R.id.percent1), (TextView) findViewById(R.id.percent2),
            (TextView) findViewById(R.id.percent3), (TextView) findViewById(R.id.percent4)};

        bindPercents(HelpUtils.calculatePercents(level, answerModels));
    }

    private void bindPercents(int[] percents) {
        for (int i = 0; i < percents.length; i++) {
            percentViews[i].setText(percents[i] + " %");

            int px = AndroidUtils.dpToPx(getContext().getResources(), 2 * percents[i]);
            LayoutParams layoutParams = rows[i].getLayoutParams();
            layoutParams.width = px;
            layoutParams.height = AndroidUtils.dpToPx(getContext().getResources(), 25);
            rows[i].setLayoutParams(layoutParams);
        }
    }

    @InjectOnClickListener(R.id.okButton)
    private void onOkClicked(View view) {
        dismiss();
    }
}
